<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>生命周期</title>
</head>
<body>
<div id="test">
    <button @click="destroyVm">destroy vm</button>
    <p v-show="isShow">hello world</p>

</div>

<script type="text/javascript" src="../js/vue.js"></script>
<script>
    // 生命周期：1 初始化显示 2 更新 3 死亡
    new Vue({
        el: '#test',
        data: {
            isShow: true
        },
        // 初始化显示后立即调用
        mounted() {
            this.intervalId = setInterval(() => {
                console.log('-----')
                this.isShow = !this.isShow
            }, 1000)
        },
        beforeDestroy(){
            // 清除定时器
            clearInterval(this.intervalId)
        },
        methods: {
            destroyVm() {
                this.$destroy()
            }
        }
    });

</script>
</body>
</html>